package leetcode.oldVersion;

import java.util.ArrayList;
import java.util.HashSet;

public class lc3 {
    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.isEmpty()) {
            return 0;
        }else if (s.length() == 1) {
            return 1;
        }
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            HashSet<Character> set = new HashSet<>();
            set.add(s.charAt(i));
            int j = i+1;
            while (j < s.length()) {
                if (!set.contains(s.charAt(j))) {
                    set.add(s.charAt(j));
                    list.add(j-i+1);
                    j++;
                }else {
                    list.add(j-i);
                    break;
                }
            }
        }
        list.sort(Integer::compareTo);
        return list.get(list.size()-1);
    }

    public static void main(String[] args) {
        String str1 = "abcabcbb";
        String str2 = "bbbbb";
        String str3 = "pwwkew";
        String str4 = "au";
        lc3 lc3 = new lc3();
        System.out.println(lc3.lengthOfLongestSubstring(str1));
        System.out.println(lc3.lengthOfLongestSubstring(str2));
        System.out.println(lc3.lengthOfLongestSubstring(str3));
        System.out.println(lc3.lengthOfLongestSubstring(str4));
    }
}
